package com.ruicar.afs.cloud.risk.tortoise.components;

import com.alibaba.fastjson.TypeReference;
import com.ruicar.afs.cloud.common.core.dynamicrequest.DynamicRequest;
import com.ruicar.afs.cloud.common.core.holder.TransRequestContextHolder;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Description
 * @Author Peng Jinbo
 * @Date 2020/07/31 20:49
 */
@Component
@Getter
@AllArgsConstructor
public class GwtInnerServerRequest {

    /**
     * Request
     */
    private final DynamicRequest request;

    /**
     * Author Peng Jinbo
     * Post *
     *
     * @param serverName server name
     * @param uri        uri
     * @param reqBody    req body
     */
    public String post(String serverName,String uri,Object reqBody){
        TransRequestContextHolder.bindSysClientInfo(null);
        return request.post(serverName,uri,reqBody);
    }

    /**
     * Author Peng Jinbo
     * Get *
     *
     * @param serverName server name
     * @param uri        uri
     * @param reqBody    req body
     */
    public String get(String serverName, String uri, Map<String,String> reqBody){
        TransRequestContextHolder.bindSysClientInfo(null);
        return request.get(serverName,uri,reqBody);
    }

    /**
     * Author Peng Jinbo
     * Post response
     *
     * @param <T>           parameter
     * @param serverName    server name
     * @param uri           uri
     * @param reqBody       req body
     * @param typeReference type reference
     * @return the response
     */
    public <T> IResponse<T> post(String serverName, String uri, Object reqBody, TypeReference<T> typeReference){
        TransRequestContextHolder.bindSysClientInfo(null);
        return request.post(serverName,uri,reqBody,typeReference);
    }

    /**
     * Author Peng Jinbo
     * Get response
     *
     * @param <T>           parameter
     * @param serverName    server name
     * @param uri           uri
     * @param reqBody       req body
     * @param typeReference type reference
     * @return the response
     */
    public <T> IResponse<T> get(String serverName, String uri, Map<String,String> reqBody,TypeReference<T> typeReference){
        TransRequestContextHolder.bindSysClientInfo(null);
        return request.get(serverName,uri,reqBody,typeReference);
    }

}
